<php>
    function _parse_vars($vars,$inputName,$level=1,$widget='',$file_id=''){
</php>
<foreach name="vars" item="var" key="varName">
    <div class="layui-form-item">
        <present name="var.title">
            <label class="layui-form-label">
                {$var.title}
                <notempty name="var.rule.require">
                    <span style="color:#FF5722;">*</span>
                </notempty>
            </label>
        </present>
        <switch name="var.type">
            <case value="text">
                <div class="layui-input-block">
                    <present name="var.dataSource">
                        <input type="text" name="{$inputName}[{$varName}_text_]" class="layui-input"
                               onclick="doSelectData(this)"
                               data-source="{:base64_encode(json_encode($var['dataSource']))}"
                               data-title="请选择{$var.title}"
                               value="{$vars[$varName]['valueText']|default=''}">
                        <input type="hidden" name="{$inputName}[{$varName}]" class="layui-input"
                               value="{$vars[$varName]['value']}">
                        <else/>
                        <input type="text" name="{$inputName}[{$varName}]" class="layui-input"
                               value="{$vars[$varName]['value']}">
                    </present>
                    <present name="var.tip">
                        <p class="help-block">{$var.tip}</p>
                    </present>
                </div>
            </case>
            <case value="textarea">
                <div class="layui-input-block">
                        <textarea name="{$inputName}[{$varName}]"
                                  class="layui-textarea">{$vars[$varName]['value']}</textarea>
                    <present name="var.tip">
                        <p class="help-block">{$var.tip}</p>
                    </present>
                </div>
            </case>
            <case value="date">
                <div class="layui-input-block">
                    <input type="text" name="{$inputName}[{$varName}]" class="layui-input js-bootstrap-date"
                           value="{$vars[$varName]['value']}">
                    <present name="var.tip">
                        <p class="help-block">{$var.tip}</p>
                    </present>
                </div>
            </case>
            <case value="datetime">
                <div class="layui-input-block">
                    <input type="text" name="{$inputName}[{$varName}]" class="layui-input js-bootstrap-datetime"
                           value="{$vars[$varName]['value']}">
                    <present name="var.tip">
                        <p class="help-block">{$var.tip}</p>
                    </present>
                </div>
            </case>
            <case value="image">
                <div class="layui-input-block">
                    <input type="hidden" name="{$inputName}[{$varName}]" class="layui-input"
                           value="{$vars[$varName]['value']}" id="js-{$widget}{$varName}-input">
                    <div>
                        <a href="javascript:uploadOneImage('图片上传','#js-{$widget}{$varName}-input');">
                            <if condition="empty($vars[$varName]['value'])">
                                <img src="__TMPL__/public/assets/images/default-thumbnail.png"
                                     id="js-{$widget}{$varName}-input-preview"
                                     width="135" style="cursor: pointer"/>
                                <else/>
                                <img src="{:cmf_get_image_preview_url($vars[$varName]['value'])}"
                                     id="js-{$widget}{$varName}-input-preview"
                                     width="135" style="cursor: pointer"/>
                            </if>
                        </a>
                        <if condition="!empty($vars[$varName]['value'])">
                            <br>
                            <button id="js-{$widget}{$varName}-button-remove"
                                    defaultImage="__TMPL__/public/assets/images/default-thumbnail.png"
                                    class="removeImage btn btn-sm" type="button"
                                    onclick="removeImage('{$widget}{$varName}')">取消图片
                            </button>
                        </if>
                    </div>
                    <present name="var.tip">
                        <p class="help-block">{$var.tip}</p>
                    </present>
                </div>
            </case>
            <case value="number">
                <div class="layui-input-block">
                    <input type="number" name="{$inputName}[{$varName}]" class="layui-input"
                           value="{$vars[$varName]['value']}">
                    <present name="var.tip">
                        <p class="help-block">{$var.tip}</p>
                    </present>
                </div>
            </case>
            <case value="location">
                <div class="layui-input-block">
                    <input type="text" name="{$inputName}[{$varName}_text_]" class="layui-input"
                           onclick="doSelectLocation(this)"
                           data-title="请选择{$var.title}"
                           value="{$vars[$varName]['valueText']|default=''}">
                    <input type="hidden" name="{$inputName}[{$varName}]" class="layui-input"
                           value="{$vars[$varName]['value']}">
                    <present name="var.tip">
                        <p class="help-block">{$var.tip}</p>
                    </present>
                </div>
            </case>
            <case value="file">
                <div class="layui-input-block">
                    <div class="input-group">
                        <input type="text" name="{$inputName}[{$varName}]" class="layui-input"
                               value="{$vars[$varName]['value']}" id="js-{$widget}{$varName}-input-file">
                        <span class="input-group-addon"> <a
                                href="javascript:uploadOne('图片上传','#js-{$widget}{$varName}-input-file','file');">上传</a></span>
                    </div>
                    <present name="var.tip">
                        <p class="help-block">{$var.tip}</p>
                    </present>
                </div>
            </case>
            <case value="color">
                <div class="layui-input-block">
                    <input type="text" name="{$inputName}[{$varName}]" class="layui-input js-color"
                           value="{$vars[$varName]['value']}" id="js-color-{$widget}{$varName}">
                    <present name="var.tip">
                        <p class="help-block">{$var.tip}</p>
                    </present>
                </div>
            </case>

            <case value="array">
                <div class="layui-input-block">
                    <php>
                        $arrayValueText=is_array($var['value'])&&count($var['value'])>0?count($var['value']).'条数据,点击添加更多...':'';
                    </php>
                    <textarea class="layui-textarea" placeholder="点击添加数据"
                              onclick="doEditArrayData(this)"
                              data-var="{$varName}"
                              data-widget="{$widget}"
                              data-title="编辑{$var.title}"
                              data-file_id="{$file_id}">{$arrayValueText}</textarea>
                    <present name="var.tip">
                        <p class="help-block">{$var.tip}</p>
                    </present>
                </div>
            </case>
            <case value="select">
                <div class="layui-input-block">
                    <php>
                        $value= $vars[$varName]['value'];
                        $options = $vars[$varName]['options'];
                    </php>
                    <select name="{$inputName}[{$varName}]" class="layui-input">
                        <foreach name="options" item="optionItem" key="optionKey">
                            <php>$optionSelected=$optionKey==$value?"selected":"";</php>
                            <option value="{$optionKey}" {$optionSelected}>{$optionItem}
                            </option>
                        </foreach>
                    </select>
                    <present name="var.tip">
                        <p class="help-block">{$var.tip}</p>
                    </present>
                </div>
            </case>
            <case value="slide">
                <div class="layui-input-block">
                    <input type="text" name="{$inputName}[{$varName}]" class="layui-input"
                           value="{$vars[$varName]['value']}">
                    <present name="var.tip">
                        <p class="help-block">{$var.tip}</p>
                    </present>
                </div>
            </case>
        </switch>
    </div>
</foreach>

<php>
    }
</php>